package edu.whu.demo.controller;


import edu.whu.demo.domain.Supplier;
import edu.whu.demo.service.ISupplierService;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 王冠儒
 * @since 2023-10-22
 */
@RestController
@RequestMapping("/supplier")
public class SupplierController {

    @Resource
    private ISupplierService supplierService;

    @GetMapping("")
    public ResponseEntity<List<Supplier>> hello(){
        return ResponseEntity.ok(supplierService.list());
    }

    @GetMapping("{supplierId}")
    public ResponseEntity<Supplier> getSupplierId(int supplierId){
        return ResponseEntity.ok(supplierService.getById(supplierId));
    }

    @PostMapping("")
    @PreAuthorize("hasAuthority('supplier/update')")
    public ResponseEntity<Void> addSupplier(@RequestBody Supplier supplier){
        supplierService.save(supplier);
        return ResponseEntity.ok().build();
    }

}

